package com.world.rickcloudendpoint.demo.redis;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.world.rickcloudendpoint.demo.QueueConstantKey;
import com.world.rickcloudendpoint.demo.RedisService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @description: 消息发送者--生产者
 * @author: jlsong
 * @date: 2022/03/17 21:58:46
 * @version: 1.0
 */
@Log4j2
@Component
public class RedisQueueSender {

    @Resource
    RedisService redisService;


    public void sendMsg(String queueName, Object message) {
        String jsonString = null;
        try {
            jsonString = QueueConstantKey.om.writeValueAsString(message);
            // 阻塞放入消息
            redisService.lLeftPush(queueName, jsonString);
        } catch (JsonProcessingException e) {
            log.error("In queue[{}]=>message convert to json str failed,the reason is {} ", queueName, e.getMessage(), e);
        }

    }
}
